home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 April: Mac OS SDK / Dev.CD Apr 99 SDK1.toast / Development Kits / Interfaces&Libraries / Universal / Interfaces / AIncludes / Math64.a < prev    next >
Encoding:
Text File  |  1998-08-17  |  11.8 KB  |  493 lines  |  [TEXT/MPS ]

  1. ;
  2. ;    File:        Math64.a
  3. ;
  4. ;    Contains:    64-bit integer math Interfaces.
  5. ;
  6. ;    Version:    Technology:    System 7.5
  7. ;                Release:    Universal Interfaces 3.2
  8. ;
  9. ;    Copyright:    © 1994-1998 by Apple Computer, Inc., all rights reserved
  10. ;
  11. ;    Bugs?:        For bug reports, consult the following page on
  12. ;                the World Wide Web:
  13. ;
  14. ;                    http://developer.apple.com/bugreporter/
  15. ;
  16. ;
  17.     IF &TYPE('__MATH64__') = 'UNDEFINED' THEN
  18. __MATH64__ SET 1
  19.  
  20.     IF &TYPE('__CONDITIONALMACROS__') = 'UNDEFINED' THEN
  21.     include 'ConditionalMacros.a'
  22.     ENDIF
  23.     IF &TYPE('__MACTYPES__') = 'UNDEFINED' THEN
  24.     include 'MacTypes.a'
  25.     ENDIF
  26.  
  27.  
  28. ; --------------------------------------------------------------------------------
  29. ;                These routines are intended to provide C software support for
  30. ;                64 bit integer types.  Their behavior should mimic anticipated
  31. ;                64 bit hardware. This implementation should replace use of the
  32. ;                "wide" type found in PowerPC.
  33. ;
  34. ;    The following routines are available for performing math on 64-bit integers:
  35. ;    
  36. ;    S64Max
  37. ;                Returns the largest representable SInt64.
  38. ;    S64Min
  39. ;                Returns the smallest (i.e. most negative) SInt64.  Note: the negative
  40. ;                (absolute value) of this number is not representable in an SInt64.
  41. ;                That means that S64Negate(S64Min) is not representable (in fact,
  42. ;                it returns S64Min).
  43. ;    S64Add
  44. ;                Adds two integers, producing an integer result.  If an overflow
  45. ;                occurs the result is congruent mod (2^64) as if the operands and
  46. ;                result were unsigned.  No overflow is signaled.
  47. ;    
  48. ;    S64Subtract
  49. ;                Subtracts two integers, producing an integer result.  If an overflow
  50. ;                occurs the result is congruent mod (2^64) as if the operands and
  51. ;                result were unsigned.  No overflow is signaled.
  52. ;
  53. ;    S64Negate
  54. ;                Returns the additive inverse of a signed number (i.e. it returns
  55. ;                0 - the number).  S64Negate (S64Min) is not representable (in fact,
  56. ;                it returns S64Min).
  57. ;    
  58. ;    S64Absolute
  59. ;                Returns the absolute value of the number (i.e. the number if
  60. ;                it is positive, or 0 - the number if it is negative).
  61. ;                See S64Negate above.
  62. ;                
  63. ;    S64Multiply
  64. ;                Multiplies two signed numbers, producing a signed result.  Overflow
  65. ;                is ignored and the low-order part of the product is returned.  The
  66. ;                sign of the result is not guaranteed to be correct if the magnitude
  67. ;                of the product is not representable.
  68. ;                
  69. ;    S64Div
  70. ;                Divides dividend by divisor, returning the quotient.  
  71. ;
  72. ;    S64Divide
  73. ;                Divides dividend by divisor, returning the quotient.  The remainder
  74. ;                is returned in *remainder if remainder (the pointer) is non-NULL.
  75. ;                The sign of the remainder is the same as the sign of the dividend
  76. ;                (i.e. it takes the absolute values of the operands, does the division,
  77. ;                then fixes the sign of the quotient and remainder).  If the divisor
  78. ;                is zero, then S64Max() will be returned (or S64Min() if the dividend
  79. ;                is negative), and the remainder will be the dividend; no error is
  80. ;                reported.
  81. ;    
  82. ;    S64Set
  83. ;                Given an SInt32, returns an SInt64 with the same value.  Use this
  84. ;                routine instead of coding 64-bit constants (at least when the
  85. ;                constant will fit in an SInt32).
  86. ;    
  87. ;    S64SetU
  88. ;                Given a UInt32, returns a SInt64 with the same value.
  89. ;    
  90. ;    S64Compare
  91. ;                Given two signed numbers, left and right, returns an
  92. ;                SInt32 that compares with zero the same way left compares with
  93. ;                right.  If you wanted to perform a comparison on 64-bit integers
  94. ;                of the form:
  95. ;                        operand_1 <operation> operand_2
  96. ;                then you could use an expression of the form:
  97. ;                        xxxS64Compare(operand_1,operand_2) <operation> 0
  98. ;                to test for the same condition.
  99. ;                
  100. ;                CAUTION: DO NOT depend on the exact value returned by this routine.
  101. ;                Only the sign (i.e. positive, zero, or negative) of the result is
  102. ;                guaranteed.
  103. ;
  104. ;    S64And, S64Or, S64Eor and S64Not
  105. ;    
  106. ;                Return Boolean (1 or 0) depending on the outcome of the logical
  107. ;                operation.
  108. ;
  109. ;    S64BitwiseAnd, S64BitwiseOr, S64BitwiseEor and S64BitwiseNot
  110. ;    
  111. ;                Return the Bitwise result.
  112. ;                
  113. ;    S64ShiftRight and S64ShiftLeft
  114. ;    
  115. ;                The lower 7 bits of the shift argument determines the amount of 
  116. ;                shifting.  S64ShiftRight is an arithmetic shift while U64ShiftRight
  117. ;                is a logical shift.
  118. ;
  119. ;    SInt64ToLongDouble
  120. ;                
  121. ;                Converts SInt64 to long double.  Note all SInt64s fit exactly into 
  122. ;                long doubles, thus, the binary -> decimal conversion routines
  123. ;                in fp.h can be used to achieve SInt64 -> long double -> decimal
  124. ;                conversions.
  125. ;                
  126. ;    LongDoubleToSInt64
  127. ;    
  128. ;                Converts a long double to a SInt64.  Any decimal string that fits
  129. ;                into a SInt64 can be converted exactly into a long double, using the
  130. ;                conversion routines found in fp.h.  Then this routine can be used
  131. ;                to complete the conversion to SInt64.
  132. ;                
  133. ;    SInt64ToWide
  134. ;    
  135. ;                Converts a SInt64 to a wide struct.  If SInt64 is implemented
  136. ;                as a typedef of wide, the marco does nothing. If SInt64 is 
  137. ;                implememnted as a long long, it casts the long long into a 
  138. ;                wide struct.
  139. ;    
  140. ;    WideToSInt64
  141. ;    
  142. ;                Converts a wide struct into a SInt64.  If SInt64 is implemented
  143. ;                as a typedef of wide, the marco does nothing. If SInt64 is 
  144. ;                implememnted as a long long, it reads the struct into a long long.
  145. ;    
  146. ;    
  147. ;    The corresponding UInt64 routines are also included.
  148. ;    
  149. ;--------------------------------------------------------------------------------
  150.  
  151.  
  152. ;
  153. ; extern SInt64 S64Max(void )
  154. ;
  155.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  156.         IMPORT_CFM_FUNCTION S64Max
  157.     ENDIF
  158.  
  159. ;
  160. ; extern SInt64 S64Min(void )
  161. ;
  162.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  163.         IMPORT_CFM_FUNCTION S64Min
  164.     ENDIF
  165.  
  166. ;
  167. ; extern SInt64 S64Add(SInt64 x, SInt64 y)
  168. ;
  169.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  170.         IMPORT_CFM_FUNCTION S64Add
  171.     ENDIF
  172.  
  173. ;
  174. ; extern SInt64 S64Subtract(SInt64 left, SInt64 right)
  175. ;
  176.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  177.         IMPORT_CFM_FUNCTION S64Subtract
  178.     ENDIF
  179.  
  180. ;
  181. ; extern SInt64 S64Negate(SInt64 value)
  182. ;
  183.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  184.         IMPORT_CFM_FUNCTION S64Negate
  185.     ENDIF
  186.  
  187. ;
  188. ; extern SInt64 S64Absolute(SInt64 value)
  189. ;
  190.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  191.         IMPORT_CFM_FUNCTION S64Absolute
  192.     ENDIF
  193.  
  194. ;
  195. ; extern SInt64 S64Multiply(SInt64 xparam, SInt64 yparam)
  196. ;
  197.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  198.         IMPORT_CFM_FUNCTION S64Multiply
  199.     ENDIF
  200.  
  201. ;
  202. ; extern SInt64 S64Divide(SInt64 dividend, SInt64 divisor, SInt64 *remainder)
  203. ;
  204.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  205.         IMPORT_CFM_FUNCTION S64Divide
  206.     ENDIF
  207.  
  208. ;
  209. ; extern SInt64 S64Set(SInt32 value)
  210. ;
  211.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  212.         IMPORT_CFM_FUNCTION S64Set
  213.     ENDIF
  214.  
  215. ;
  216. ; extern SInt64 S64SetU(UInt32 value)
  217. ;
  218.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  219.         IMPORT_CFM_FUNCTION S64SetU
  220.     ENDIF
  221.  
  222. ;
  223. ; extern SInt32 S32Set(SInt64 value)
  224. ;
  225.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  226.         IMPORT_CFM_FUNCTION S32Set
  227.     ENDIF
  228.  
  229. ;
  230. ; extern int S64Compare(SInt64 left, SInt64 right)
  231. ;
  232.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  233.         IMPORT_CFM_FUNCTION S64Compare
  234.     ENDIF
  235.  
  236. ;
  237. ; extern Boolean S64And(SInt64 left, SInt64 right)
  238. ;
  239.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  240.         IMPORT_CFM_FUNCTION S64And
  241.     ENDIF
  242.  
  243. ;
  244. ; extern Boolean S64Or(SInt64 left, SInt64 right)
  245. ;
  246.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  247.         IMPORT_CFM_FUNCTION S64Or
  248.     ENDIF
  249.  
  250. ;
  251. ; extern Boolean S64Eor(SInt64 left, SInt64 right)
  252. ;
  253.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  254.         IMPORT_CFM_FUNCTION S64Eor
  255.     ENDIF
  256.  
  257. ;
  258. ; extern Boolean S64Not(SInt64 value)
  259. ;
  260.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  261.         IMPORT_CFM_FUNCTION S64Not
  262.     ENDIF
  263.  
  264. ;
  265. ; extern SInt64 S64BitwiseAnd(SInt64 left, SInt64 right)
  266. ;
  267.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  268.         IMPORT_CFM_FUNCTION S64BitwiseAnd
  269.     ENDIF
  270.  
  271. ;
  272. ; extern SInt64 S64BitwiseOr(SInt64 left, SInt64 right)
  273. ;
  274.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  275.         IMPORT_CFM_FUNCTION S64BitwiseOr
  276.     ENDIF
  277.  
  278. ;
  279. ; extern SInt64 S64BitwiseEor(SInt64 left, SInt64 right)
  280. ;
  281.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  282.         IMPORT_CFM_FUNCTION S64BitwiseEor
  283.     ENDIF
  284.  
  285. ;
  286. ; extern SInt64 S64BitwiseNot(SInt64 value)
  287. ;
  288.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  289.         IMPORT_CFM_FUNCTION S64BitwiseNot
  290.     ENDIF
  291.  
  292. ;
  293. ; extern SInt64 S64ShiftRight(SInt64 value, UInt32 shift)
  294. ;
  295.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  296.         IMPORT_CFM_FUNCTION S64ShiftRight
  297.     ENDIF
  298.  
  299. ;
  300. ; extern SInt64 S64ShiftLeft(SInt64 value, UInt32 shift)
  301. ;
  302.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  303.         IMPORT_CFM_FUNCTION S64ShiftLeft
  304.     ENDIF
  305.  
  306. ;    "long double" means 128 bit type on PowerPC and 80-bit type on 68K
  307. ;
  308.  
  309. ;
  310. ; extern long double SInt64ToLongDouble(SInt64 value)
  311. ;
  312.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  313.         IMPORT_CFM_FUNCTION SInt64ToLongDouble
  314.     ENDIF
  315.  
  316. ;
  317. ; extern SInt64 LongDoubleToSInt64(long double value)
  318. ;
  319.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  320.         IMPORT_CFM_FUNCTION LongDoubleToSInt64
  321.     ENDIF
  322.  
  323. ;
  324. ; extern UInt64 U64Max(void )
  325. ;
  326.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  327.         IMPORT_CFM_FUNCTION U64Max
  328.     ENDIF
  329.  
  330. ;
  331. ; extern UInt64 U64Add(UInt64 x, UInt64 y)
  332. ;
  333.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  334.         IMPORT_CFM_FUNCTION U64Add
  335.     ENDIF
  336.  
  337. ;
  338. ; extern UInt64 U64Subtract(UInt64 left, UInt64 right)
  339. ;
  340.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  341.         IMPORT_CFM_FUNCTION U64Subtract
  342.     ENDIF
  343.  
  344. ;
  345. ; extern UInt64 U64Multiply(UInt64 xparam, UInt64 yparam)
  346. ;
  347.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  348.         IMPORT_CFM_FUNCTION U64Multiply
  349.     ENDIF
  350.  
  351. ;
  352. ; extern UInt64 U64Divide(UInt64 dividend, UInt64 divisor, UInt64 *remainder)
  353. ;
  354.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  355.         IMPORT_CFM_FUNCTION U64Divide
  356.     ENDIF
  357.  
  358. ;
  359. ; extern UInt64 U64Set(SInt32 value)
  360. ;
  361.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  362.         IMPORT_CFM_FUNCTION U64Set
  363.     ENDIF
  364.  
  365. ;
  366. ; extern UInt64 U64SetU(UInt32 value)
  367. ;
  368.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  369.         IMPORT_CFM_FUNCTION U64SetU
  370.     ENDIF
  371.  
  372. ;
  373. ; extern UInt32 U32SetU(UInt64 value)
  374. ;
  375.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  376.         IMPORT_CFM_FUNCTION U32SetU
  377.     ENDIF
  378.  
  379. ;
  380. ; extern int U64Compare(UInt64 left, UInt64 right)
  381. ;
  382.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  383.         IMPORT_CFM_FUNCTION U64Compare
  384.     ENDIF
  385.  
  386. ;
  387. ; extern Boolean U64And(UInt64 left, UInt64 right)
  388. ;
  389.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  390.         IMPORT_CFM_FUNCTION U64And
  391.     ENDIF
  392.  
  393. ;
  394. ; extern Boolean U64Or(UInt64 left, UInt64 right)
  395. ;
  396.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  397.         IMPORT_CFM_FUNCTION U64Or
  398.     ENDIF
  399.  
  400. ;
  401. ; extern Boolean U64Eor(UInt64 left, UInt64 right)
  402. ;
  403.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  404.         IMPORT_CFM_FUNCTION U64Eor
  405.     ENDIF
  406.  
  407. ;
  408. ; extern Boolean U64Not(UInt64 value)
  409. ;
  410.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  411.         IMPORT_CFM_FUNCTION U64Not
  412.     ENDIF
  413.  
  414. ;
  415. ; extern UInt64 U64BitwiseAnd(UInt64 left, UInt64 right)
  416. ;
  417.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  418.         IMPORT_CFM_FUNCTION U64BitwiseAnd
  419.     ENDIF
  420.  
  421. ;
  422. ; extern UInt64 U64BitwiseOr(UInt64 left, UInt64 right)
  423. ;
  424.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  425.         IMPORT_CFM_FUNCTION U64BitwiseOr
  426.     ENDIF
  427.  
  428. ;
  429. ; extern UInt64 U64BitwiseEor(UInt64 left, UInt64 right)
  430. ;
  431.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  432.         IMPORT_CFM_FUNCTION U64BitwiseEor
  433.     ENDIF
  434.  
  435. ;
  436. ; extern UInt64 U64BitwiseNot(UInt64 value)
  437. ;
  438.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  439.         IMPORT_CFM_FUNCTION U64BitwiseNot
  440.     ENDIF
  441.  
  442. ;
  443. ; extern UInt64 U64ShiftRight(UInt64 value, UInt32 shift)
  444. ;
  445.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  446.         IMPORT_CFM_FUNCTION U64ShiftRight
  447.     ENDIF
  448.  
  449. ;
  450. ; extern UInt64 U64ShiftLeft(UInt64 value, UInt32 shift)
  451. ;
  452.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  453.         IMPORT_CFM_FUNCTION U64ShiftLeft
  454.     ENDIF
  455.  
  456. ;    "long double" means 128 bit type on PowerPC and 80-bit type on 68K
  457. ;
  458.  
  459. ;
  460. ; extern long double UInt64ToLongDouble(UInt64 value)
  461. ;
  462.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  463.         IMPORT_CFM_FUNCTION UInt64ToLongDouble
  464.     ENDIF
  465.  
  466. ;
  467. ; extern UInt64 LongDoubleToUInt64(long double value)
  468. ;
  469.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  470.         IMPORT_CFM_FUNCTION LongDoubleToUInt64
  471.     ENDIF
  472.  
  473. ;
  474. ; extern SInt64 UInt64ToSInt64(UInt64 value)
  475. ;
  476.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  477.         IMPORT_CFM_FUNCTION UInt64ToSInt64
  478.     ENDIF
  479.  
  480. ;
  481. ; extern UInt64 SInt64ToUInt64(SInt64 value)
  482. ;
  483.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  484.         IMPORT_CFM_FUNCTION SInt64ToUInt64
  485.     ENDIF
  486.  
  487.  
  488.  
  489.     ENDIF ; __MATH64__ 
  490.  
  491.